﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace TuongLai_Schools
{
    public class cls_DM_BuoiHoc
    {

        //public clsDM_BuoihocCollection Getlist_DM_Buoihoc()
        //{
        //    clsDM_BuoihocCollection DM_BuoihocCollection = new clsDM_BuoihocCollection();
        //    DbAccess db = new DbAccess();
        //    db.CreateNewSqlCommand_Text();
        //    SqlDataReader reader = db.ExecuteReader("Select BuoiHocID,TenBuoiHoc,GhiChu,isChangeable from DM_BuoiHoc");
        //    while (reader.Read())
        //    {
        //        clsDM_Buoihoc objdm_Buoihoc = new clsDM_Buoihoc();
        //        objdm_Buoihoc.BuoiHocID = (int)reader["BuoiHocID"];
        //        objdm_Buoihoc.TenBuoiHoc = reader["TenBuoiHoc"].ToString();
        //        objdm_Buoihoc.GhiChu = reader["GhiChu"].ToString();
        //        objdm_Buoihoc.isChangeable = (bool)reader["isChangeable"];
        //        DM_BuoihocCollection.Add(objdm_Buoihoc);
        //    }
        //    reader.Close();
        //    return DM_BuoihocCollection;     
        //}
      //  public DataTable dataTable;
        //==========================================================================
        //SqlCommand cmd;
        //public void Save_Buoihoc()
        //{
        //    try
        //    {
        //        SqlDataAdapter sqldtAdp_Buoihoc = new SqlDataAdapter();
        //        cmd.CommandText = "Select BuoiHocID,TenBuoiHoc,GhiChu,isChangeable from DM_BuoiHoc";
        //        sqldtAdp_Buoihoc.SelectCommand = cmd;
        //        new SqlCommandBuilder(sqldtAdp_Buoihoc);
        //      //  sqldtAdp_Buoihoc.Update(dataTable);
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }
        //}


        public DataTable GetAll_Buoihoc()
        {
            DbAccess db = new DbAccess();
            db.CreateNewSqlCommand_Text();
            DataTable dataTable = db.ExecuteDataTable("Select BuoiHocID,TenBuoiHoc,GhiChu,isChangeable from DM_BuoiHoc");
            return dataTable;
        }
             
        public bool Insert(clsDM_Buoihoc obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@BuoiHocID", obj.BuoiHocID);
                db.AddParameter("@TenBuoiHoc", obj.TenBuoiHoc);
                db.AddParameter("@GhiChu", obj.GhiChu);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.ExecuteNonQuery("insert into DM_BuoiHoc(TenBuoiHoc,GhiChu,isChangeable) values(N'" + obj.TenBuoiHoc + "',N'" + obj.GhiChu + "','" + obj.isChangeable + "')");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool update(clsDM_Buoihoc obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@BuoiHocID", obj.BuoiHocID);
                db.AddParameter("@TenBuoiHoc", obj.TenBuoiHoc);
                db.AddParameter("@GhiChu", obj.GhiChu);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.ExecuteNonQuery("update DM_BuoiHoc set TenBuoiHoc=N'" + obj.TenBuoiHoc + "',GhiChu=N'" + obj.GhiChu + "',isChangeable='" + obj.isChangeable + "' where BuoiHocID='" + obj.BuoiHocID + "'");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool delete(int BuoiHocid)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@BuoiHocID", BuoiHocid);
                db.ExecuteNonQuery("delete DM_BuoiHoc where BuoiHocID='" + BuoiHocid + "'");
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
